<template>
  <view>
    <view class="home_tab">
      <view class="home_tab_title">
        <view class="title_inner">
          <uni-segmented-control :current="current" :values="items.map(v=>v.title)" @clickItem="onClickItem" style-type="text" active-color="#d4237a"></uni-segmented-control>
        </view>
        <view class="iconfont icon--search"></view>
      </view>
      <view class="home_tab_content">
        <view v-if="current === 0">
          <home-recommend></home-recommend>
        </view>
        <view v-if="current === 1">
          <home-category></home-category>
        </view>
        <view v-if="current === 2">
          <home-new></home-new>
        </view>
        <view v-if="current === 3">
          <home-album></home-album>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import homeRecommend from './home-recommend/index'
import homeNew from './home-new/index'
import homeCategory from './home-category/index'
import homeAlbum from './home-album/index'
import uniSegmentedControl from "@/components/uni-segmented-control/uni-segmented-control.vue"
  export default {
    data() {
      return {
        items: [{title:"推荐"},{title:"分类"},{title:"最新"},{title:"专辑"}],
        current: 1
      }
    },
    components:{
      homeRecommend,
      homeNew,
      homeCategory,
      homeAlbum,
      uniSegmentedControl
    },
    methods:{
      onClickItem(e) {
        if (this.current !== e.currentIndex) {
          this.current = e.currentIndex;
        }
      }
    },
    onLoad(){
      //this.request()
    }
  }
</script>

<style lang="scss" scoped>
.home_tab {
  .home_tab_title {
    position: relative;
    .title_inner {
      width: 60%;
      margin: 0 auto;
    }

    .icon--search {
      position: absolute;
      top: 50%;
      transform: translateY(-50%);
      right: 5px;
    }
  }

  .home_tab_content {
     font-size: 14px;
  }
}
</style>